package com.pan.behavioral.command.order.impl;

import com.pan.behavioral.command.order.MyCommand;
import com.pan.behavioral.command.order.MyScreenCommand;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class PrintScreen extends MyScreenCommand {

    private Robot robot;{
        try {
            robot = new Robot();
        } catch (AWTException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void execute() {
        Rectangle screenRect = new Rectangle(x,y,width,height);
        BufferedImage screen = robot.createScreenCapture(screenRect);
        JFrame frame = new JFrame("print screen frame");
        frame.setDefaultCloseOperation(2);
        JLabel jLabel = new JLabel(new ImageIcon(screen));
        frame.add(jLabel);
        frame.pack();
        frame.setVisible(true);

    }

}
